<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title>商品管理</title>
		<link rel="stylesheet" href="__AGENT__/css/iconfont.css" />
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css"  media="all">
		<style type="text/css">
			.spgl_right{float: right;}
			.spgl_right a{background-color: #007AFF; border-radius: 3px; margin-right: 15px; display: inline-block; color: #fff;padding:3px 10px;font-size: 14px;}
			.spgl_right a:hover,.shangj_btn:hover{color: white;}
			.orders_content{margin-top: 15px;}
			.shangj_btn{background-color: #FF7831; border-radius: 3px;color: #fff;padding:3px 10px;}
		</style>
	</head>

	<body>
		{include file="public/header" /}
		<div class="index_conbox">
			<div class="index_content clearfix">
				{include file="public/lefter" /}
				<div class="right">
					<div class="rigtop">
						<span class="title">商品管理</span>
						<span class="spgl_right">
							<a href="javascript:;" onclick="goods_add()">新增商品</a>
							<a href="{:url('shop/goods_type')}" >新增分类</a>
							<a href="{:url('shop/export_goods')}" >批量导入</a>
							<a onclick="check()">批量导出</a>
						</span>
					</div>
					<div class="indrig_con orders_con">
					
						<form id="my_form" action="{:url('agent/shop/goods_manage')}" method="post">
						<div class="spfl_topbox clearfix">
							<div class="chax_rowbox clearfix">
								<div class="zizh_con_1">
									<div class="shxx_row chax_row clearfix" id='cut_time'>
							            <div class="left">上架时间：</div>
							            <div class="right clearfix">
							                <div class="layui-inline">
										      <div class="layui-input-inline">
										        <input type="text" class="layui-input" name="begin_time" id="begin_time" placeholder="yyyy年MM月dd日">
										      </div>
										    </div>
							                <i class="chax_line"></i>
							                <div class="layui-inline">
										      <div class="layui-input-inline">
										        <input type="text" class="layui-input" name="end_time"  id="end_time" placeholder="yyyy年MM月dd日">
										      </div>
										    </div>
							            </div>
							        </div>
								</div>
							</div>
								<div class="shxx_row clearfix">
						            <div class="left">商品编号：</div>
						            <div class="right clearfix">
										<input type="text" name="goods_no" id="goods_no" placeholder="输入商品编号" class="chax_input" />
						            </div>
						            <div class="left" style="margin-left: 10px;">商品名称：</div>
						            <div class="right clearfix">
						                <input type="text" name="goods_name" id="goods_name" placeholder="输入商品名称" class="chax_input" />
						            </div>
						        </div>
							<div class="chax_rowbox clearfix">
								<div class="shxx_row clearfix">
						            <span class="level_flbt">商品分类：</span>
									<span class="level_fl {if $type_id==0}active{/if}"><a href="{:url('agent/shop/goods_manage')}">全部</a></span>
									{volist name="goods_type" id="vo"}
										<a  href="{:url('agent/shop/goods_manage',['type_id'=>$vo.id])}"><span class="level_fl {if $type_id==$vo.id}active{/if}">{$vo.type_name}</span></a>
									{/volist}
						        </div>
						        <div class="shxx_row clearfix">
						            <button type="submit" onclick="return check_time()" class="htcxbtn">搜索</button>
						            
						        </div>
							</div>
						</div>
						</form>
						<a href="javascript:;" class="shangj_btn" onclick="chuli(2)">上架</a>
						<a href="javascript:;" class="shangj_btn" onclick="chuli(1)">下架</a>
						<a href="javascript:;" class="shangj_btn" onclick="chuli(4)">设为推荐</a>
						<a href="javascript:;" class="shangj_btn" onclick="chuli(3)">取消推荐</a>
						<a href="javascript:;" class="shangj_btn" onclick="to_qr_code()">二维码下载</a>
						<a href="javascript:;" class="shangj_btn" onclick="chuli(5)">批量删除</a>
						<a href="javascript:;" class="shangj_btn" onclick="select_store()">选择门店</a>
						<a href="javascript:;" class="shangj_btn" onclick="select_sort()">修改分类</a>
						<div class="orders_content">
							<table class="zizh_table1">
								<thead>
									<tr>
										<th style="width: 30px;">
											<input type="checkbox" onclick="check_all(this)" />
										</th>
										<th>序号</th>
										<th>商品编号</th>
										<th>商品名称</th>
										<th>商品分类</th>
										<th>零售价/送</th>
										<th>会员价/抵</th>
										<th>库存</th>
										<th>门店</th>
										<th>添加时间</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody id="tbody">
									{volist name="goods_list" id="vo" empty="$empty"}
									<tr>
										<td><input type="checkbox" name="chk[]" value='{$vo.goods_id}'> </td>
										<td>{$i+($goods_list->currentPage()-1)*20}</td>
										<td><a class="iconfont icon-erweima"  href="javascript:;" onclick="goods_code('{$vo.goods_id}')"></a>{$vo.goods_no}</td>
										<td>{$vo.goods_name}</td>
										<td>{$vo.type_name}</td>
										<td>
											{$vo.sale_price}
											送{$vo.zs_price}
										</td>
										<td>
											{$vo.sale_price - $vo.dk_price}
											+{$vo.dk_price}
										</td>
										<td>{$vo.stock}</td>
										<td>{$vo.store_name?$vo.store_name : '通用'}</td>
										<td>{$vo.addtime|substr=0,10}</td>
										<td>
											{if condition="$vo.goods_state == 2"}
												<a href="javascript:;" onclick="shangjia('{$vo.goods_id}','1')">下架</a>
											{else /}
												<a href="javascript:;" class="gray" onclick="shangjia('{$vo.goods_id}','2')">上架</a>
											{/if}
											{if condition="$vo.is_recommend == 2"}
												<a href="javascript:;" onclick="tuijian('{$vo.goods_id}','1')">不推荐</a>
											{else /}
												<a href="javascript:;" onclick="tuijian('{$vo.goods_id}','2')">推荐</a>
											{/if}
											<a href="javascript:;" class="gray" onclick="goods_edit('{:url('shop/goods_edit',['goods_id'=>$vo.goods_id])}')">编辑</a>
											<a class="ajax-delete" href="{:url('agent/shop/del_goods',['goods_id'=>$vo.goods_id])}">删除</a>
										</td>
									</tr>
									{/volist}
								</tbody>
							</table>
							<div class="fenye" style="display: block;">
								{$goods_list->render()}
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		{include file="public/footer" /}
	</body>

</html>
<script type="text/javascript" src="__PUBLIC__/static/js/assist.js"></script>
<script type="text/javascript">
	
	//调取添加商品页面
	function goods_add() {
		layer.open({
		  type: 2,
		  title: '发布商品',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['900px', '740px'],
		  content: "{:url('shop/goods_add')}"
		}); 
	}
	
	
	//调取添加商品页面
	function to_qr_code() {
		var chsub = $("input[name='chk[]']:checked").length;
		if (chsub > 0) {
			var arr_id ="";
			$("input[name='chk[]']:checked").each(function(){
				var id=$(this).val()+",";
				arr_id+=id;
			})
		}else{
			layer.msg("请选择要下载的二维码的商品!");
			return ;
		}
		var url = "/agent/shop/down_qr_code.html?id="+arr_id;
		layer.open({
		  type: 2,
		  title: '下载二维码',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['900px', '740px'],
		  content:	url
		}); 
	}
	
	function check_all(obj){
		$ck=$(obj).prop("checked");
		$("tbody :checkbox, #all").prop("checked",$ck);
		
	}
	function chuli(status) {
		var chsub = $("input[name='chk[]']:checked").length;
		if (chsub > 0) {
			var lay=layer.confirm('确认操作?', {
			icon: 3,
			title: '提示'
			}, function(index) {
				layer.close(lay);
				var arr=new Array();
				$("input[name='chk[]']:checked").each(function(){
					var id=$(this).val();
					arr.push(id);
				})
				$.ajax({
						url:"{:url('shop/chuli')}",
						data:{arr:arr,status:status},
						type:"post",
						success: function(data) {
							layer.msg(data.msg);
							if(data.code==200){
								window.location.reload();
							}
								
						}
				})
			});
		} else {
			layer.msg("请选择操作对象!");
			return ;
		}
	}

	function goods_code(goods_id) {
				var url = 'goods_code?goods_id='+goods_id;
				layer.open({
				  type: 2,
				  title: '单商品二维码',
				  shadeClose: true,
				  shade: 0.8,
				  area: ['426px', '730px'],
				  content: [url]
				}); 
	}
	//调取修改商品页面
	function goods_edit(url) {
		layer.open({
		  type: 2,
		  title: '编辑商品',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['900px', '740px'],
		  content: url
		}); 
	}

	layui.use('laydate', function(){
		var laydate = layui.laydate;
		
		//日期控件
		laydate.render({
		    elem: '#begin_time'
		    ,type: 'datetime'
		    ,format: 'yyyy-MM-dd HH:mm:ss'
		});
		  
		laydate.render({
		    elem: '#end_time'
		    ,type: 'datetime'
		    ,format: 'yyyy-MM-dd HH:mm:ss'
		});
	})

	//商品分类
	$('#to_goods_tpe').click(function(){
		location.href = "{:url('shop/goods_type')}";
	})
	
	//时间区间
	function check_time(){
		var begin_time 	= $('#begin_time').val();
		var end_time 	= $('#end_time').val();	
		if(begin_time.length > 2 || end_time.length > 2){
			
			if(begin_time.length < 2 || end_time.length < 2){
				layer.msg("请输入查询时间区间");
				return false;
			}
			
		}
	}
	
	function shangjia(id,goods_state){
		layer.confirm('您确定要修改吗？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$.ajax({
				url: "{:url('shop/shangjia')}",
				data: {
					id:id,
					goods_state:goods_state
				},
				success: function(data) {
					if(data.code==200){
	                	layer.msg('修改成功', {
						  icon: 1,
						  time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							location.href = "{:url('shop/goods_manage')}";
						});
	                }else{
	                	layer.msg('修改失败！');
	                }
				}
			})
		})
	}
	
	//推荐
	function tuijian(id,is_recommend){
		layer.confirm('您确定要修改吗？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$.ajax({
				url: "{:url('shop/tuijian')}",
				data: {
					id:id,
					is_recommend:is_recommend
				},
				success: function(data) {
					if(data.code==200){
	                	layer.msg('修改成功', {
						  icon: 1,
						  time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							location.href = "{:url('shop/goods_manage')}";
						});
	                }else{
	                	layer.msg('修改失败！');
	                }
				}
			})
		})
	}
	
	function select_store(){
		var chsub = $("input[name='chk[]']:checked").length;
		if (chsub > 0) {
				var arr=new Array();
				var id_list ='';
				$("input[name='chk[]']:checked").each(function(){
					var id=$(this).val();
					id_list +=id+',';
				})
				
				var url = "/agent/shop/select_store.html?id_list="+id_list;
				
				layer.open({
				  type: 2,
				  title: '选择分类',
				  shadeClose: true,
				  shade: 0.8,
				  area: ['520px', '160px'],
				  content: url
				}); 
		} else {
			layer.msg("请选择操作对象!");
			return ;
		}
	}
	
	function select_sort(){
		var chsub = $("input[name='chk[]']:checked").length;
		if (chsub > 0) {
				var arr=new Array();
				var id_list ='';
				$("input[name='chk[]']:checked").each(function(){
					var id=$(this).val();
					id_list +=id+',';
				})
				
				var url = "/agent/shop/select_sort.html?id_list="+id_list;
				
				layer.open({
				  type: 2,
				  title: '选择分类',
				  shadeClose: true,
				  shade: 0.8,
				  area: ['520px', '160px'],
				  content: url
				}); 
		} else {
			layer.msg("请选择操作对象!");
			return ;
		}
	}

	//导出
	function check() {
		var begin_time = $('#begin_time').val();
		var end_time = $('#end_time').val();
		var goods_no = $('#goods_no').val();
		var goods_name = $('#goods_name').val();	
		var type_id = '{$type_id}';
		window.location.href = "/agent/shop/exportout_dc.html?begin_time=" + begin_time + "&end_time=" + end_time
		+ "&goods_no=" + goods_no + "&goods_name=" + goods_name + "&type_id=" + type_id;
	}




</script>
